package scream.servlet.usuario;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import scream.excepcion.DAOExcepcion;
import scream.negocio.SeguridadNegocioUsuario;

/**
 * Servlet implementation class for Servlet: RolInsertarServlet
 * 
 */
@WebServlet("/UsuarioInsertarServlet")
public class UsuarioInsertarServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#HttpServlet()
	 */
	public UsuarioInsertarServlet() {
		super();
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

	/*
	 * (non-Java-doc)
	 * 
	 * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request,
	 * HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub

		String a = request.getParameter("txtCodigo");
		String b = request.getParameter("txtClave");
		String c = request.getParameter("txtPaterno");
		String d = request.getParameter("txtMaterno");
		String e = request.getParameter("txtNombre");
		String f = request.getParameter("txtDni");
		String g = request.getParameter("cboRol");
		//System.out.println(g);
		SeguridadNegocioUsuario negocio = new SeguridadNegocioUsuario();
		if(a.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		if(b.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		if(c.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		if(d.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		if(e.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		if(f.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		if(g.equals("")){
			request.getRequestDispatcher("errorIngreso.jsp").forward(request, response);
			return;
		}
		try {
			negocio.insertarUsuario(a,b,c,d,e,f,g);
			response.sendRedirect(request.getContextPath()
					+ "/UsuarioBuscarServlet");
		} catch (DAOExcepcion e1) {
			RequestDispatcher rd = request.getRequestDispatcher("errorUsuario.jsp");
			rd.forward(request, response);
		}

	}
}